package com.tencent.cloud.iov.util.backdoor;

import android.app.Activity;
import android.view.View;

import com.tencent.cloud.iov.util.log.LogManager;
import com.tencent.tac.social.share.FileObject;
import com.tencent.tac.social.share.TACShareDialog;

/**
 * 分享日志：连续点击 3 次首页"社区" Tab 按钮
 *
 * @author showxiao
 * @date 2018/9/14
 */
public class ShareLogListener implements View.OnClickListener {

    private static final int MIN_CLICK_COUNT = 3;

    private int mContinuousClickCount = 0;
    private long mLastClickTime = 0;

    private final Activity mActivity;

    public ShareLogListener(Activity activity) {
        mActivity = activity;
    }

    @Override
    public void onClick(View v) {
        long curTime = System.currentTimeMillis();
        if (mLastClickTime == 0 || curTime - mLastClickTime < 500) {
            ++mContinuousClickCount;

            if (mContinuousClickCount >= MIN_CLICK_COUNT) {
                shareLogFile();
                mContinuousClickCount = 0;
            }
        } else {
            mContinuousClickCount = 0;
        }

        mLastClickTime = curTime;

    }

    private void shareLogFile() {
        TACShareDialog shareDialog = new TACShareDialog();
        shareDialog.share(mActivity, new FileObject(LogManager.getLogFilePath(mActivity)));
    }
}
